import { defineStore } from "pinia";
export const menuStore = defineStore("menuStore", {
  state: () => ({
    navTree: [], // 导航菜单树
    orderNavTree: [], // 导航菜单树
  }),
  getters: {
    navTreeList(state) {
      return state.navTree;
    },
    getOrderNavTree(state) {
      return state.orderNavTree;
    },
    menuChilds: (state) => (navTree, name) => {
      return navTree[0].children.filter((nav) => {
        return nav.meta.title == name;
      });
    },
    // menuChilds: state => (navTree, name) => {
    //   var list;
    //   navTree[0].children.forEach(nav => {
    //     if (nav.name == name) {
    //       list = nav;
    //     } else if (nav.children) {
    //       list = nav.children.filter(item => {
    //         return item.meta.title == name;
    //       });
    //     }
    //   });
    //   return list;
    // }
  },
  actions: {
    setNavTree(navTree) {
      this.navTree = navTree;
    },
    setOrderNavTree(orderNavTree) {
      this.orderNavTree = orderNavTree;
    },
  },
});
